<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.27.2/axios.js"></script>
  </head>
  <body>
    <h1>axios里的拦截器</h1>
    <button class="btn1">请求一</button>
    <button class="btn2">请求二</button>
    <script>
      //1. 请求拦截器 : 里是回调函数 ，接收的参数 是 config
      axios.interceptors.request.use(function (config) {
        config.headers.token = "dhsjabdhjasd";
        console.log("执行了请求拦截器");
        return config;
      });

      //   2.返还拦截器
      axios.interceptors.response.use(function (response) {
        console.log("返还拦截器", response);
        // 数据的在加工
        return response;
      });
    </script>
  </body>
</html>
